<?php

/**
 * Configuration Class
 * Singleton
 * 
 * @author Ben Rowe
 */
class Configuration
{
	/**
	 * stores the configuration hash of keys/values
	 *
	 * @access public
	 * @var array
	 */
	var $_hash = array();

	/**
	 * get the requested key from the configuration hash.
	 * if the key doesn't exist then $default is returned
	 *
	 * @access public
	 * @param string $key
	 * @param mixed $default
	 * @return mixed
	 */
	function get($key, $default = null)
	{
		if(array_key_exists($key, $this->_hash)) {
			return $this->_hash[$key];
		}
		return $default;
	}
	
	/**
	 * Enter a key into the configuration hash
	 *
	 * @access public
	 * @param string $key
	 * @param mixed $value
	 * @return boolean
	 */
	function set($key, $value)
	{
		$this->_hash[$key] = $value;
		return true;
	}
	
	/**
	 * load the configuration from the database
	 *
	 * @access public
	 * @return boolean
	 */
	function load()
	{
		$sql	= "SELECT `key`, `value` FROM `configuration`";
		$result	= mysql_query($sql);
		while($row = mysql_fetch_assoc($result)) {
			$this->set($row['key'], $row['value']);
		}
		return true;
	}
}

?>